package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo4Filter {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName("Demo4Filter")
      .setMaster("local")

    val sc = new SparkContext(conf)

    //构建rdd

    val listRDD: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5, 6, 7, 8))

    /**
      * filter: 对rdd中的数据进行过滤，函数返回true保留数据，函数返回false过滤数据
      *
      * filter: 转换算子，懒执行
      */

    val filterRDD: RDD[Int] = listRDD.filter(i => {
      i % 2 == 1
    })

    filterRDD.foreach(println)



  }

}
